package com.itheima.util;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Random;

/*
随机生成各种数据的工具类

 */
public class RandomUtil {
    private RandomUtil() {
    }

    private static Random r = new Random();
    private static StringBuilder zimus = new StringBuilder();

    static {
        for (int i = 'A'; i <= 'Z'; i++) {
            zimus.append((char) i);
        }
        for (int i = 'a'; i <= 'z'; i++) {
            zimus.append((char) i);
        }
        for (int i = '0'; i <= '9'; i++) {
            zimus.append((char) i);
        }
    }

    //生成姓名
    public static String randomName() {
        ArrayList<String> danlist = NameUtil.danXing();
        ArrayList<String> fulist = NameUtil.fuXing();
        ArrayList<String> ziList = NameUtil.getZi();
        int i = r.nextInt(20);
        String name = "";
        if (i == 19) {
            name += fulist.get(r.nextInt(fulist.size()));
        } else {
            name += danlist.get(r.nextInt(danlist.size()));
        }
        int j = r.nextInt(8);
        if (j == 0) {
            name += ziList.get(r.nextInt(ziList.size()));
        } else {
            name += ziList.get(r.nextInt(ziList.size()));
            name += ziList.get(r.nextInt(ziList.size()));
        }
        return name;
    }

    //生成 性别
    public static String randomGender() {
        int j = r.nextInt(2);
        if (j == 0) {
            return "男";
        } else {
            return "女";
        }
    }

    //随机生日
    public static LocalDate randomBirthday() {
        LocalDate jizhun = LocalDate.of(1995, 1, 1);
        LocalDate localDate = jizhun.plusYears(r.nextInt(11)).plusMonths(r.nextInt(13)).plusDays(r.nextInt(32));
        return localDate;
    }

    public static String randomPhone() {
        StringBuilder sb = new StringBuilder("1");
        for (int i = 0; i < 10; i++) {
            sb.append(r.nextInt(10));
        }
        return sb.toString();
    }

    public static ArrayList<String> randomWxs() {
        ArrayList<String> list = new ArrayList<>();
        int j = r.nextInt(2);
        if (j == 0) {
            list.add(getWx());
        } else {
            list.add(getWx());
            list.add(getWx());
        }
        return list;
    }

    private static String getWx() {
        int count = r.nextInt(11) + 10;
        StringBuilder wx = new StringBuilder();
        for (int i = 0; i < count; i++) {
            int index = r.nextInt(zimus.length());
            wx.append(zimus.toString().charAt(index));
        }
        return wx.toString();
    }


}
